﻿Imports System.IO
Imports ScintillaNet
Imports ScintillaNet.Configuration

Public Class ScintillaEditor
    Inherits Scintilla

    Public Sub New()
        Dim editortheme As String = Globals.EditorSettings.GetTrait("EditorTheme", "themes/dark.xml")

        Me.Dock = DockStyle.Fill

        Lexing.LexerLanguageMap.Add("us", "cpp")

        ChangeTheme(editortheme)

        LineNumbers =
            Globals.EditorSettings.GetTrait(Of Boolean)("LineNumbers", True)

    End Sub

    Property LineNumbers As Boolean
        Get
            Return Margins(0).Width > 0
        End Get
        Set(ByVal value As Boolean)
            If value Then
                Margins(0).Width = 30
            Else
                Margins(0).Width = 0
            End If
        End Set
    End Property

    Public Sub ChangeTheme(ByRef themepath As String)
        ConfigurationManager.IsUserEnabled = True
        ConfigurationManager.IsBuiltInEnabled = True
        ConfigurationManager.LoadOrder = ConfigurationLoadOrder.CustomUserBuiltIn
        ConfigurationManager.CustomLocation = themepath
        ConfigurationManager.Language = "us"
        ConfigurationManager.Configure()

        ' Adjust the color of the caret
        Me.Caret.Color = Me.Styles.Default.ForeColor
    End Sub

    Private Sub InitializeComponent()
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ScintillaEditor
        '
        Me.Styles.BraceBad.FontName = "Verdana"
        Me.Styles.BraceLight.FontName = "Verdana"
        Me.Styles.ControlChar.FontName = "Verdana"
        Me.Styles.Default.FontName = "Verdana"
        Me.Styles.IndentGuide.FontName = "Verdana"
        Me.Styles.LastPredefined.FontName = "Verdana"
        Me.Styles.LineNumber.FontName = "Verdana"
        Me.Styles.Max.FontName = "Verdana"
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
End Class
